<?php
/* TODO: Add code here */
require('config/globalconfig.php');
?>
<?php
include_once('classes/user_sphinx_search.php');
include_once('classes/user_product.php');
include_once('classes/user_property.php');
include_once('classes/user_faq.php');
include_once('classes/user_catalogue.php');
//user_common::writeLog('insert',0);
$objProduct = new user_product($objConnection);
$objProperty = new user_property($objConnection);
$objFAQ = new user_faq($objConnection);

//$objProduct->insert('1','1','1','1');
if ($_pgR["act"]==user_product::ACT_ADD)
{
	if (user_common::isCLogin())
	{
		//lấy thông tin user
		//$c_userInfo = $_SESSION[consts::SES_C_USERINFO];
		
		$strProperty = $_pgR['property'];
		$arrProperty = explode(user_common::STRING_SEPARATE_1,$strProperty);
		//print_r($arrProperty);
		$strNameProperty = $arrProperty[0];
		$strValueProperty = $arrProperty[1];
		
		$resultID = $objProduct->insert($_pgR['manu'],$_pgR['cat'],user_common::formatOutputText($_pgR['name']));
		$objProperty->insertPropertyBatch($resultID,$_pgR['sect'],'1', $strNameProperty,$strValueProperty) ;
		
		//thêm phần bang cau hoi
		$strFAQ = $_pgR['faq'];
		$arrFAQ = explode(user_common::STRING_SEPARATE_1,$strFAQ);
		//print_r($arrProperty);
		$strQuestion = $arrFAQ[0];
		$strAnswer = $arrFAQ[1];
		
		$objFAQ->insertFaqBatch($resultID,'1', $strQuestion,$strAnswer) ;
		if ($resultID)
		{
			$arrHeader = user_common::getMessageHeaderArr($banCode);//$banCode
			//echo $strHeaderMessage."1".consts::SEP_RESPONSE.$strResultHTML.consts::SEP_RETURN.$_pgR["ontop"];
			echo user_common::convertToXML(
					$arrHeader, array("rs", "inf"), 
					array(1, $result ), 
					array( 0, 1 )
					);
			return;
		}
	}
	echo user_common::convertToXML($arrHeader, array("rs"), array(0), array(0));
	return;
}
elseif($_pgR['act'] == user_product::ACT_CHANGE_PAGE)
{
	$intPage = $_pgR['p'];
	
	$outPutHTML =  $objProduct->getListProduct($intPage);
	echo user_common::convertToXML($strMessageHeader, array('rs','inf'), array(1,$outPutHTML),array(0,1));
	return ;
}

if(isset($_pgR['sct']))
{
	$keyword = $_pgR['sct'];
	$indexName = 't_faq';
	$user_sphinx = new user_sphinx_search($objConnection,$indexName);
	$arrFAQ = $user_sphinx->search_for_keyword($keyword,0,user_sphinx_search::NUM_RECORD_FOR_TABLE,$strFilter);
	$arrResultFAQ= $objFAQ->getFaqByIDs($arrFAQ);
	//print_r($arrFAQ);
	//echo '<br>';
	//print_r($arrResult);
	//xuất chuỗi html search
	$strHTMLFAQ = $objFAQ->outputHTMLSearch($arrResultFAQ,$keyword);
	
	
	$indexName = 't_product';
	$user_sphinx = new user_sphinx_search($objConnection,$indexName);
	$arrProduct = $user_sphinx->search_for_keyword($keyword,0,user_sphinx_search::NUM_RECORD_FOR_TABLE);
	//print_r($arrProduct);
	$strHTMLProduct = $objProduct->outputHTMLProductSearch($arrProduct);
}

// echo 'callcenter';
// user_common::writeLog("anc",1);


include_once('include/_header.inc');
include_once('include/_menu.inc');
include_once('include/_search_box.inc');
?>
<script type="text/javascript" src="<?php echo $_objSystem->locateJs('user_admin_product.js');?>"></script>
<script type="text/javascript" src="<?php echo $_objSystem->locateJs('ajaxupload.js');?>"></script>


	
<!--Begin Form Input -->
<input type="hidden" id="adddocmode" name="adddocmode" value="1<?php //echo $intMode;?>" />
<input type="hidden" id="txtPage" name="txtPage" value="<?php echo $_pgR["p"]?$intPage:1;?>" />

<?php echo $strHTMLFAQ; ?>

<?php 
//echo Product HTML
echo $strHTMLProduct; ?>

<?php 
//footer
include_once('include/_footer.inc');
?>